<!-- 页面外套 -->
<div class="page-wrapper" id="business_public_provider_get">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped">
        <!-- 工具条组 -->
        <div class="tool-group">
            <form class="tool-search">
                <input type="hidden" name='page'>
                <input type="hidden" name='recPerPage'>
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" name="sid">
                            <option value="1">姓名</option>
                            <option value="2">手机</option>
                            <option value="3">公司</option>
                            <option value="4">业务员</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" name="search">
                    </div>
                </div>
                <label>
                    <span>级别：</span>
                    <select class="form-control" name="level">
                        <option value="0">全部</option>
                        <option value="1">A</option>
                        <option value="2">B</option>
                        <option value="3">C</option>
                        <option value="4">D</option>
                        <option value="5">E</option>
                    </select>
                </label>
                <label><button type="button" class="btn btn-primary tool_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </form>
            <div class="tool-deal">
                <label><button class="btn btn-primary tool_belongs_btn"><i class="icon icon-flag"></i> 隶属于我</button></label>
                <div class="clearfix"></div>
            </div>
        </div>

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
  
    <!-- 隶属于我盒子(列表多个) -->
    <div class="modal modal-for-page fade tool_belongs_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">隶属于我</h4>
                </div>
                <div class="modal-body">
                    <div class="container">
                        <p>您确定要将选中的信息员隶属于自己名下吗？</p>
                        <form><input type="hidden" name="ids"></form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary tool_belongs_submit">提交</button>
                </div>               
            </div>
        </div>
    </div>

</div>
<!-- page-wrapper -->

<!-- 详情外套 -->
<div class="detail-wrapper mode-show" id="business_public_provider_get_detail">
    
    <!-- 详情弹框 -->
    <div class="modal modal-for-page fade detail_box" aria-hidden="false">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">可抢信息员详情</h4>
                </div>
                <div class="modal-body modal-scroll">

                    <!-- 操作按钮 -->
                    <button class="btn" data-dismiss="modal"><i class="icon icon-arrow-left"></i> 返回</button>
                    <label><button class="btn btn-primary"  data-toggle="modal" data-target=".detail_belong_box">隶属于我</button></label>

                    <!-- 数据表单 -->
                    <form class="detail_box_form">
                        <input type="hidden" name="cid">
                        <table class="table"><!--JS推进--></table>
                    </form>

                    <!-- 切换表格 -->
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-tab="" href=".detail_tab1">回访记录</a></li>
                        <li><a data-tab="" href=".detail_tab2">客户记录</a></li>
                        <li><a data-tab="" href=".detail_tab3">信息费记录</a></li>
                        <li><a data-tab="" href=".detail_tab4">提成记录</a></li>
                        <li><a data-tab="" href=".detail_tab5">过程记录</a></li>
                    </ul>

                    <div class="tab-content">
                        <div class="tab-pane active detail_tab1">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab2">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab3">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab4">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                        <div class="tab-pane detail_tab5">
                            <form class="tool-search">
                                <input type="hidden" name='page'>
                                <input type="hidden" name='recPerPage'>
                                <input type="hidden" name="cid" value="null">
                            </form>
                            <div class="datagrid datagrid-striped">
                                <div class="datagrid-container"></div>
                                <ul class="pager btn-mini" data-elements="first_icon,prev_icon,next_icon,last_icon,size_menu,goto,page_of_total_text" data-menu-direction="dropup"></ul>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <!-- 隶属于我盒子(详情单个) -->
    <div class="modal modal-for-page fade detail_belong_box" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">隶属于我</h4>
                </div>
                <div class="modal-body">
                    <div class="container">
                        <p>您确定要将此信息员隶属于自己名下吗？</p>
                        <form><input type="hidden" name="cid"></form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary detail_belong_submit">提交</button>
                </div>               
            </div>
        </div>
    </div>

</div>

<script>
$(function() {
    //变量声明-----------------------------------------------------------------------------------------------
    var business_public_provider_get = $("#business_public_provider_get"); //页面ID
    var business_public_provider_get_api = {
        datagrid : API.test_datagrid, // 数据表格
        belongs : API.test_response, // 工具条-隶属于我(列表多个)
        belong : API.test_response, // 工具条-隶属于我(详情单个)
        show : LOCAL + "Test/Template/provider.json", // 详情查看
        tab1 : API.test_datagrid, // 切换表格1
        tab2 : API.test_datagrid, // 切换表格2
        tab3 : API.test_datagrid, // 切换表格3
        tab4 : API.test_datagrid, // 切换表格4
        tab5 : API.test_datagrid, // 切换表格5
    }

    //数据表格-----------------------------------------------------------------------------------------------
    //数据源
    var business_public_provider_get_dataSource = {
        cols   : [
            {name:"name",label:"姓名",width:80,html:true,
                valueOperator : {
                    getter : function(dataValue,cell){
                        return `<a class="line_show_btn" dataId="${cell.config.data.id}">${dataValue}</a>`;
                    }
                }
            },
            {name:"tex10",   label:"公司名称",    width:150},
            {name:"text5",   label:"工作性质",    width:100},
            {name:"name",    label:"业务员",      width:80 },
            {name:"text2",   label:"级别",        width:80 },
            {name:"datetime",label:"上次回访时间",width:140},
            {name:"tex10",   label:"上次回访内容",width:200},
            {name:"text4",   label:"回访过期",    width:100}
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get, 
                url      : business_public_provider_get_api.datagrid
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get,
                data     : data
            });
        }
    };
    //实例化
    business_public_provider_get.find('.datagrid').datagrid(
        zui_datagrid_option({
            datagrid   : business_public_provider_get.find('.datagrid'),
            dataSource : business_public_provider_get_dataSource,
            checkable   : true,
        })
    );
    var business_public_provider_get_datagrid_obj = business_public_provider_get.find('.datagrid').data("zui.datagrid");
    //搜索
    business_public_provider_get.find('.tool_search_btn').click(function(){ 
        zui_datagrid_render({
            datagrid_obj : business_public_provider_get_datagrid_obj,
            dataSource   : business_public_provider_get_dataSource
        }); 
    });

    //操作按钮-------------------------------------------------------------------------------------------
    //工具条-隶属于我(列表多个)
    var business_public_provider_get_belongs_box = business_public_provider_get.find('.tool_belongs_box');
    business_public_provider_get.on("click", '.tool_belongs_btn', function() {
        var data_arr = business_public_provider_get_datagrid_obj.getCheckItems().filter(function(e){return e});
        if( data_arr.length>0 ){
            var data_id = [];
            for(var i=0;i<data_arr.length;i++){
                data_id.push(data_arr[i].id);
            }
            business_public_provider_get_belongs_box.find('[name="ids"]').val( data_id.join(",") );
            business_public_provider_get_belongs_box.modal("show");
        } else {
            um_tip("至少选择一条数据","1000","text-danger");
        }
    });
    business_public_provider_get.on("click", '.tool_belongs_submit', function() {
        um_data_submit({
            url: business_public_provider_get_api.belongs,
            form: business_public_provider_get_belongs_box.find('form'),
            dataSource: business_public_provider_get_dataSource,
        });
    });
 
    //详情部分---------------------------------------------------------------------------
    //变量声明
    var business_public_provider_get_detail = $("#business_public_provider_get_detail");
    var business_public_provider_get_detail_dataSource_tab1 = {
        cols   : [
            {name:"name",    label:"回访人",      width:80 },
            {name:"tex10",   label:"回访内容",    width:200},
            {name:"datetime",label:"回访时间",    width:140},
            {name:"datetime",label:"下次回访时间",width:140},
            {name:"text2",   label:"是否有效",    width:80 },
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get_detail.find('.detail_tab1'), 
                url      : business_public_provider_get_api.tab1
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get_detail.find('.detail_tab1'),
                data     : data
            });
        }
    }
    var business_public_provider_get_detail_dataSource_tab2 = {
        cols   : [
            {name:"username",label:"项目编号",    width:80 },
            {name:"text5",   label:"客户名称",    width:140},
            {name:"name",    label:"联系人1",     width:80 },
            {name:"name",    label:"业务员",      width:80 },
            {name:"name",    label:"主案设计师",  width:90 },
            {name:"text2",   label:"房源状态",    width:80 },
            {name:"text2",   label:"面积",        width:80 },
            {name:"datetime",label:"上次回访时间",width:140},
            {name:"tex10",   label:"上次回访内容",width:200},
            {name:"text2",   label:"回访剩余",    width:80 },
            {name:"text2",   label:"状态",        width:80 },
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get_detail.find('.detail_tab2'), 
                url      : business_public_provider_get_api.tab2
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get_detail.find('.detail_tab2'),
                data     : data
            });
        }
    }
    var business_public_provider_get_detail_dataSource_tab3 = {
        cols   : [
            {name:"username",label:"项目编号",    width:80 },
            {name:"text5",   label:"客户名称",    width:140},
            {name:"name",    label:"信息员",      width:80 },
            {name:"name",    label:"业务员",      width:80 },
            {name:"name",    label:"主案设计师",  width:90 },
            {name:"datetime",label:"申请时间",    width:140},
            {name:"text2",   label:"申请金额",    width:80 },
            {name:"text2",   label:"状态",        width:80 }
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get_detail.find('.detail_tab3'), 
                url      : business_public_provider_get_api.tab3
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get_detail.find('.detail_tab3'),
                data     : data
            });
        }
    }
    var business_public_provider_get_detail_dataSource_tab4 = {
        cols   : [
            {name:"username",label:"项目编号",    width:80 },
            {name:"text5",   label:"客户名称",    width:140},
            {name:"name",    label:"业务员",      width:80 },
            {name:"name",    label:"主案设计师",  width:90 },
            {name:"text2",   label:"签单金额",    width:80 },
            {name:"datetime",label:"申请时间",    width:140},
            {name:"text2",   label:"申请提点",    width:80 },
            {name:"text2",   label:"应发提成",    width:80 },
            {name:"text2",   label:"实发提成",    width:80 },
            {name:"text2",   label:"状态",        width:80 }
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get_detail.find('.detail_tab4'), 
                url      : business_public_provider_get_api.tab4
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get_detail.find('.detail_tab4'),
                data     : data
            });
        }
    }
    var business_public_provider_get_detail_dataSource_tab5 = {
        cols   : [
            {name:"name",    label:"操作人",  width:80 },
            {name:"datetime",label:"操作时间",width:140},
            {name:"tex10",   label:"过程说明",width:200},
        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : business_public_provider_get_detail.find('.detail_tab5'), 
                url      : business_public_provider_get_api.tab5
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : business_public_provider_get_detail.find('.detail_tab5'),
                data     : data
            });
        }
    }

    //详情弹框
    business_public_provider_get.on("click", '.line_show_btn', function() {
        common_form_reset();
        var dataId = $(this).attr('dataId');
        business_public_provider_get_detail.find('[name="cid"]').val(dataId); // 详情ID赋值(多个)
        //远程请求
        $.ajax({
            url     : business_public_provider_get_api.show,
            type    : "post",
            dataType: "json",
            data    : { id: dataId },
            success : function(data){
                if( data.status>0 ){
                    var data = data.data;
                    //基础表格
                    var temp = `
                    <thead><tr><td colspan="3"><b>业务员</b>${data.salesman}</td></tr></thead>
                    <tbody>
                        <tr>
                            <td><div class="flex-box"><b>姓名 </b>${data.user1}</div></td>
                            <td><div class="flex-box"><b>姓名2</b>${data.user2}</div></td>
                            <td><div class="flex-box"><b>手机1</b>${data.tel1} </div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>手机2</b>${data.tel2}</div></td>
                            <td><div class="flex-box"><b>手机3</b>${data.tel3}</div></td>
                            <td><div class="flex-box"><b>手机4</b>${data.tel4}</div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>银行名称</b>${data.bankname}</div></td>
                            <td><div class="flex-box"><b>开户人</b>${data.bankuser}</div></td>
                            <td><div class="flex-box"><b>银行卡号</b>${data.bankcard}</div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>公司名称</b>${data.company}</div></td>
                            <td><div class="flex-box"><b>服务区域</b>${data.area}</div></td>
                            <td><div class="flex-box"><b>身份证号</b>${data.idcard}</div></td>
                        </tr>
                        <tr>
                            <td><div class="flex-box"><b>生日</b>${data.birthday}</div></td>
                            <td><div class="flex-box"><b>级别</b>${data.levelname}</div></td>
                            <td><div class="flex-box"><b>工作性质</b>${data.typename}</div></td>
                        </tr>
                        <tr><td colspan="3"><div class="flex-box" style="height:35px;"><b>备注信息</b>${data.text}</div></td></tr>
                    </tbody>
                    `;
                    business_public_provider_get_detail.find('.detail_box .detail_box_form table').html(temp); // DOM填充
                    //切换表格刷新
                    zui_datagrid_render({
                        datagrid_obj : business_public_provider_get_detail.find('.detail_tab1 .datagrid').data("zui.datagrid"),
                        dataSource   : business_public_provider_get_detail_dataSource_tab1
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_public_provider_get_detail.find('.detail_tab2 .datagrid').data("zui.datagrid"),
                        dataSource   : business_public_provider_get_detail_dataSource_tab2
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_public_provider_get_detail.find('.detail_tab3 .datagrid').data("zui.datagrid"),
                        dataSource   : business_public_provider_get_detail_dataSource_tab3
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_public_provider_get_detail.find('.detail_tab4 .datagrid').data("zui.datagrid"),
                        dataSource   : business_public_provider_get_detail_dataSource_tab4
                    });
                    zui_datagrid_render({
                        datagrid_obj : business_public_provider_get_detail.find('.detail_tab5 .datagrid').data("zui.datagrid"),
                        dataSource   : business_public_provider_get_detail_dataSource_tab5
                    });
                    business_public_provider_get_detail.find('.detail_box').modal('show'); // 弹框显示
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });
 
    });

    //操作按钮-隶属于我(详情单个)
    business_public_provider_get_detail.on("click", '.detail_belong_submit', function() {
        um_data_submit({
            url: business_public_provider_get_api.belong,
            form: business_public_provider_get_detail.find('.detail_belong_box form'),
            dataSource: business_public_provider_get_dataSource,
        });
    });

    //切换表格-回访记录------------------------------------------------------------------------
    business_public_provider_get_detail.find('.detail_tab1 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_public_provider_get_detail.find('.detail_tab1 .datagrid'),
            dataSource : business_public_provider_get_detail_dataSource_tab1
        })
    );
    //切换表格-客户记录
    business_public_provider_get_detail.find('.detail_tab2 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_public_provider_get_detail.find('.detail_tab2 .datagrid'),
            dataSource : business_public_provider_get_detail_dataSource_tab2
        })
    );
    //切换表格-信息费记录
    business_public_provider_get_detail.find('.detail_tab3 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_public_provider_get_detail.find('.detail_tab3 .datagrid'),
            dataSource : business_public_provider_get_detail_dataSource_tab3
        })
    );
    //切换表格-提成记录
    business_public_provider_get_detail.find('.detail_tab4 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_public_provider_get_detail.find('.detail_tab4 .datagrid'),
            dataSource : business_public_provider_get_detail_dataSource_tab4
        })
    );
    //切换表格-过程记录
    business_public_provider_get_detail.find('.detail_tab5 .datagrid').datagrid(
        zui_datagrid_option({
            height     : 400,
            datagrid   : business_public_provider_get_detail.find('.detail_tab5 .datagrid'),
            dataSource : business_public_provider_get_detail_dataSource_tab5
        })
    );

}); //预加载结尾
</script>